package com.tcoiss.app.controller;

import com.tcoiss.app.domain.GdAdminDivision;
import com.tcoiss.app.service.IGdAdminDivisionService;
import com.tcoiss.common.core.utils.poi.ExcelUtil;
import com.tcoiss.common.core.web.controller.BaseController;
import com.tcoiss.common.core.web.domain.AjaxResult;
import com.tcoiss.common.core.web.page.TableDataInfo;
import com.tcoiss.common.log.annotation.Log;
import com.tcoiss.common.log.enums.BusinessType;
import com.tcoiss.common.security.annotation.PreAuthorize;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 高德行政区划Controller
 * 
 * @author zw
 * @date 2021-10-22
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/admindivision" )
public class GdAdminDivisionController extends BaseController {

    private final IGdAdminDivisionService iGdAdminDivisionService;

    /**
     * 查询高德行政区划列表
     */
    @PreAuthorize(hasPermi = "webservice:admindivision:list")
    @GetMapping("/list")
    public TableDataInfo list(GdAdminDivision gdAdminDivision) {
        startPage();
        List<GdAdminDivision> list = iGdAdminDivisionService.getList(gdAdminDivision);
        return getDataTable(list);
    }

    /**
     * 导出高德行政区划列表
     */
    @PreAuthorize(hasPermi = "webservice:admindivision:export" )
    @Log(title = "高德行政区划" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,GdAdminDivision gdAdminDivision) throws IOException
    {
        List<GdAdminDivision> list = iGdAdminDivisionService.getList(gdAdminDivision);
        ExcelUtil<GdAdminDivision> util = new ExcelUtil<GdAdminDivision>(GdAdminDivision.class);
        util.exportExcel(response,list, "admindivision" );
    }

    /**
     * 获取高德行政区划详细信息
     */
    @PreAuthorize(hasPermi = "webservice:admindivision:query" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGdAdminDivisionService.getById(id));
    }

    /**
     * 新增高德行政区划
     */
    //@PreAuthorize(hasPermi = "webservice:admindivision:add" )
    @Log(title = "高德行政区划" , businessType = BusinessType.INSERT)
    @GetMapping("/initData")
    public AjaxResult initData() {
        return toAjax(iGdAdminDivisionService.initData() ? 1 : 0);
    }





}
